import axios from 'axios'
import qs from 'qs'

axios.defaults.timeout = 0;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
axios.defaults.baseURL = 'http://192.168.9.252:9090';

axios.interceptors.request.use(config => {
    if(config.method === 'post'){
        config.data = qs.stringify(config.data)
    }
    return config
},(error) => {
    return Promise.reject(error)
});

axios.interceptors.response.use((response) => {
    return response
},(error) => {
    return Promise.reject(error)
});

const Api =  {
        /*获取短信验证码*/
        getCode : function(param){
            return axios.post('/yd-front/borrower/user/sendSmsCode',param)
        },
        /*登录*/
        login : function (param) {
            return axios.post('/yd-front/borrower/user/login',param)
        },
        /*登出*/
        loginout : function (param) {
            return axios.post('/yd-front/borrower/user/logout',param)
        },
        /*获取图形验证码*/
        getImgCode : function () {
            return axios.get('/yd-front//borrower/captcha/getCaptcha',{
                params:{
                    width:100,
                    height:40
                },
                responseType:'arraybuffer'
            })
        },
        /*获取借款人信息*/
        getBorrowUserInfo : function (param) {
            return axios.post('/yd-front/borrower/user/getBorrowUserInfo',param)
        },
        /*获取时间戳*/
        getTimeStamp : function () {
            return axios.get('/yd-front/borrower/user/getTimestamp')
        },
        /*激活账户*/
        activiAccount : function (param) {
            return axios.post('/yd-front/borrower/user/userAccountInfoActive',param)
        },
        /*获取个人中心待还款和已还款金额*/
        getAmount : function (param) {
            return axios.post('/yd-front/borrower/account/getBorrowerAccountRepaymentInfo',param)
        },
        /*获取我的资产中的待还款记录*/
        getRepaymentInfo : function (param) {
            return axios.post('/yd-front/borrower/account/getBorrowerAccountWaitRepaymentList',param)
        },
        /*获取我的借款*/
        getborrowList : function (param) {
            return axios.get('/yd-front/borrower/sproject/list',param)
        },
        /*借款详情*/
        getBorrowDetail : function (param) {
            return axios.get('/yd-front/borrower/sproject/detail',param)
        },
        /*合同列表*/
        getContractList : function (param) {
            return axios.get('/yd-front/borrower/sproject/sinvestmentdetail/list',param)
        },
        /*合同详情*/
        getContractDetail : function (param) {
            return axios.get('/yd-front/borrower/sproject/sinvestmentdetail/detail',param)
        },
        /*还款计划*/
        getRepayPlan : function (param) {
            return axios.get('/yd-front/borrower/sproject/suserduedetail/list',param)
        }
}


export default Api